package com.yc.blog.springboot.event.ctr;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yc.blog.springboot.event.demo1.MyEvent1;

@Controller
public class MyController {
	
	@Autowired
	private ApplicationEventPublisher applicationEventPublisher;
	
	@ResponseBody
	@RequestMapping("/test1")
	public String test1() {
		System.out.println("----发布1开始-------");
		MyEvent1 event = new MyEvent1(this, "新消息1");
		applicationEventPublisher.publishEvent(event);//发布者发布消息
		System.out.println("----发布1完成-------");
		return "success";
	}
	
	@RequestMapping("/test2")
	@ResponseBody
	public String test2() {
		System.out.println("---------test2--------");
		return "success";
	}

}
